class Solution:
    def isBipartite(self, graph) -> bool:
        set1 = set()
        set2 = set()
        if len(graph)<=0:
            return True
        for g in range(len(graph)):
            if len(graph[g]) == 0:
                continue
            set1.add(g)
            nowPeriod = set()
            nowPeriod.add(g)
            while len(nowPeriod):
                tmp = set()

                for i in nowPeriod:
                    if len(graph[i]) == 0:
                        continue
                    for key in graph[i]:
                        if key in set1:
                            return False
                        if key not in set2:
                            tmp.add(key)
                            set2.add(key)
                    graph[i] = []

                nowPeriod = tmp
                set1,set2 = set2,set1
        return True

if __name__ == '__main__':
    so = Solution()
    nums1 = [[4],[],[4],[4],[0,2,3]]
    r = so.isBipartite(nums1)
    print(r)
